package com.itboye.hutouben.activity.mysetting;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itboye.hutouben.R;
import com.itboye.hutouben.base.BaseActivity;
import com.itboye.hutouben.base.MyApplcation;
import com.itboye.hutouben.phouto.ImagePagerActivity;
import com.itboye.hutouben.phouto.NoScrollGridAdapter;
import com.itboye.hutouben.phouto.NoScrollGridView;
import com.itboye.hutouben.util.Const;
import com.itboye.hutouben.util.XImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by itboye on 2017/1/3.
 */

public class ActivityWeiXiuXiangqing extends BaseActivity {

    TextView add_shap_title_tv, tvweixiu01, tvweixiu02, tvweixiu03, tvweixiu04;
    String WeiXiu1, WeiXiu2, WeiXiu3, WeiXiu4,WeiXiu5;
    ArrayList<String> infoList = new ArrayList<String>();
    NoScrollGridView gridview;
    ImageView close_icon;
    LinearLayout img0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_weixiuxiangqing);
        add_shap_title_tv.setText("维修详情");
        WeiXiu1 = getIntent().getStringExtra("WeiXiu1");//维修统计
        WeiXiu2 = getIntent().getStringExtra("WeiXiu2");//材料费用
        WeiXiu3 = getIntent().getStringExtra("WeiXiu3");//维修费用
        WeiXiu4 = getIntent().getStringExtra("WeiXiu4");
        WeiXiu5 = getIntent().getStringExtra("WeiXiu5");
        infoList = getIntent().getStringArrayListExtra("info");
        tvweixiu01.setText("¥:" +Double.parseDouble(WeiXiu1)/100);
        tvweixiu02.setText("¥:" + Double.parseDouble(WeiXiu2)/100);
        tvweixiu03.setText("¥:" + Double.parseDouble(WeiXiu3)/100);
        tvweixiu04.setText(WeiXiu4 + "");
        Log.d("infofifnfiof", infoList.size() + "");
//        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                // TODO Auto-generated method stub
//                imageBrower(position, infoList);
//            }
//        });
        String str = WeiXiu5;// 原始字符串

        String[] arrayStr = new String[]{};// 字符数组
        List<String> lists = new ArrayList<String>();// list

        arrayStr = str.split(",");// 字符串转字符数组
        lists = java.util.Arrays.asList(arrayStr);// 字符数组转list
        String[] storeStr = lists.toArray(new String[lists.size()]);// list转成字符数组
        img0.removeAllViews();
        /* 输出字符数组的值 */
        for (final String s : arrayStr) {
            System.out.println(s);


            if (s == null || s.equals("")) {
                img0.setVisibility(View.GONE);
            } else if (storeStr.length <= 0) {

                img0.setVisibility(View.GONE);
            } else if (storeStr.length >= 1) {
                img0.setVisibility(View.VISIBLE);
                View v = LayoutInflater.from(MyApplcation.ctx).inflate(R.layout.layout_items, null);
                ImageView img1 = (ImageView) v.findViewById(R.id.img1);
                XImageLoader.load(Const.IMAGE_HEAD + s, img1);
                ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(
                        ViewGroup.MarginLayoutParams.WRAP_CONTENT,
                        ViewGroup.MarginLayoutParams.WRAP_CONTENT);
                layoutParams.setMargins(5, 5, 5, 5);
                img1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        Intent intent=new Intent(MyApplcation.ctx,ImageVieMaxActivyt.class);
                        intent.putExtra("id",s);
                        startActivity(intent);
                    }
                });
                img0.addView(v, layoutParams);
            }

        }
    }

    /**
     * 打开图片查看器
     *
     * @param position
     * @param urls2
     */
    protected void imageBrower(int position, ArrayList<String> urls2) {
        Intent intent = new Intent(mContext, ImagePagerActivity.class);
        // 图片url,为了演示这里使用常量，一般从数据库中或网络中获取
        intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, urls2);
        intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, position);
        startActivity(intent);
    }

    @Override
    protected void onInit() {

    }

    @Override
    protected void onReadIntent(Bundle bundle) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.close_icon:
                finish();
                break;
        }
    }

}
